package gogogo.liwushuo.app;

import android.app.Application;
import android.util.DisplayMetrics;

import android.graphics.Bitmap;

import com.squareup.picasso.LruCache;
import com.squareup.picasso.Picasso;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

/**
 * Created by Puck on 2016/7/20.
 */
public class IApp extends Application {
    public static int mScreenHeight;
    public static int mScreenWidth;

    @Override
    public void onCreate() {
        super.onCreate();
        initScreen();
        initPicasso();
        initImageLoader();
    }

    //初始化全局的图片配置信息
    private void initImageLoader() {
        //自定义设置全局信息
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
                .diskCacheSize(30 * 1024 * 1024)
                .memoryCacheSize(10 * 1024 * 1024)
                .build();
        ImageLoader.getInstance().init(config);
        //使用默认的全局配置信息
//        ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(this));

    }

    /**
     * 初始化屏幕的宽高
     * 抽取方法的快捷键：ctrl+alt+m
     */
    private void initScreen() {
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        mScreenHeight = displayMetrics.heightPixels;
        mScreenWidth = displayMetrics.widthPixels;
    }

    private void initPicasso() {
        Picasso picasso = new Picasso.Builder(this)
                .memoryCache(new LruCache(10<<20))
                .defaultBitmapConfig(Bitmap.Config.RGB_565)
                .build();
        Picasso.setSingletonInstance(picasso);
    }

}